package com.history.admin.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.history.service.api.model.Person;
import com.history.service.api.service.PersonService;

@Controller
@RequestMapping("/test")
public class HelloWorldController {

	@Autowired
	PersonService personService;
	
	@RequestMapping("/helloWord")
    public ModelAndView helloWord(HttpServletRequest request, HttpServletResponse response,String cp) throws Exception {  
		ModelAndView mv = new ModelAndView("test");  
        mv.addObject("title", "Spring MVC And velocity");  
        mv.addObject("content", " Hello world ， test my first spring mvc ! ");  
        return mv;  
    } 
	
	@RequestMapping("/getPersonById")
    public ModelAndView getPersonById(HttpServletRequest request, HttpServletResponse response,Long id) throws Exception {  
		ModelAndView mv = new ModelAndView("test");  
		Person person=personService.selectById(id);
        mv.addObject("person", JSON.toJSONString(person, true));
        return mv;  
    } 
}
